<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="demo" index="1" class="index"> </div>
    <script>
        var div = document.querySelector('div');
        console.log(div.id);
        console.log(div.getAttribute('id'));
        console.log(div.getAttribute('index'));
        div.id = 'test';
        div.className = 'navs';
        //主要针对自定义属性
        div.setAttribute('index', 2);
        div.setAttribute('class', 'fotter');
        //移除属性 removeAttribute(属性)
        div.removeAttribute('index');
    </script>
</body>

</html>